package com.hmall.order.utils;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.hmall.order.mapper.OrderMapper;
import com.hmall.order.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.sql.Date;
import java.util.List;

@Component
public class TestTask {

    @Autowired
    private OrderMapper orderMapper;

    //               秒  分  时 天 月 周
    @Scheduled(cron = "*/10 * * * * ?") // 每隔10秒
    public void handleTast(){
        List<Order> orderList = orderMapper.selectList(null);
        for (Order order : orderList) {
            if (order.getStatus() == 1) {
                Date createTime = order.getCreateTime();
                long time = createTime.getTime();
                System.out.println("时间:"+time);
                long nowTime = System.currentTimeMillis();
                System.out.println("现在的时间" +
                        ""+nowTime);
                if ((nowTime - time) - 10000 > 0) {
                    LambdaUpdateWrapper<Order> wrapper = new LambdaUpdateWrapper<>();
                    wrapper.eq(Order::getId,order.getId())
                            .set(Order::getStatus,5);
                    orderMapper.update(null,wrapper);
                    System.out.println("执行完成 已经进入");
                }
            }
        }
    }

}
